<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\City;
use App\Traits\Controllers\AdminTraits;
use Illuminate\Http\Request;

class CityController extends Controller
{
    use AdminTraits;

    public $model = City::class;

    function index()
    {
      //从缓存中抓取数据
        return cache_city();

    }

    //清除缓存
    function forgetCity()
    {

        return forget_city_cache();
    }


    /**
     * 参数验证规则
     *
     * @param Request $request
     * @return array
     */
    public function rules(Request $request): array
    {
        switch ($request->method()) {
            case 'GET':
                return [];
                break;
            case 'PATCH':
            case 'POST':
            case 'PUT':
                return [
                    'name' => 'required',
                    'pid' => 'required',
                    'level' => 'required',

                ];
                break;


        }
        return [];
    }

    /**
     * 验证信息
     *
     * @return array
     */
    public function ruleMessages(): array
    {
        return [
            'name.required'=>'城市名称不能为空',
            'pid.required'=>'上级城市不能为空',
            'level.required'=>'城市级别不能为空'
        ];
    }


}

